import React from 'react'
import { Switch, Redirect, Route, RouteComponentProps } from 'react-router-dom'
import { IRouteItem } from '../utils/interface'
interface Iprops{
  routes:IRouteItem[]
}
const RouterView: React.FC<Iprops> = (props) => {
  return (
    <Switch>
      {
        props.routes.map((item, index) => {
          if (item.redirect) {
           return <Redirect key={item.path} from={item.path} to={item.redirect}></Redirect>
          }
          return <Route key={item.path} path={item.path} render={(routerProps:RouteComponentProps) => {
             return <item.component {...routerProps} routes={item.children}></item.component>
          }}></Route>
        })
      }
    </Switch>
  )
  
}
export default RouterView